package com.wsj.util.tool;

import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
 
/**
 *
 * @author Zhang Yu
 *
 */
 
public class DiscuzEncryption {
 
 public static String generateKey(String src, String algorithm) {
  MessageDigest m = null;
  try
  {
   m = MessageDigest.getInstance(algorithm);
   m.update(src.getBytes("UTF8"));
  }
  catch (NoSuchAlgorithmException e)
  {
   e.printStackTrace();
  }
  catch (UnsupportedEncodingException e)
  {
   e.printStackTrace();
  }
  byte s[] = m.digest();
  String result = "";
  for (int i = 0; i < s.length; i++)
  {
   result += Integer.toHexString(
     (0x000000FF & s[i]) | 0xFFFFFF00).substring(6);
  }
  return result;
 }
}

